package reflection;

public class Test07 {
    public static void main(String[] args) throws ClassNotFoundException {

        // 获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);// sun.misc.Launcher$AppClassLoader@18b4aac2

        // 获得拓展类加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);// sun.misc.Launcher$ExtClassLoader@1b6d3586

        // 尝试获得引导类加载器
        ClassLoader rootClassLoader = parent.getParent();
        System.out.println(rootClassLoader);// null。BootStrapClassLoader不能直接获取

        // 当前类是由哪个类加载器加载的？答案是AppClassLoader
        ClassLoader currentClassLoader = Class.forName("reflection.Test07").getClassLoader();
        System.out.println(currentClassLoader);// sun.misc.Launcher$AppClassLoader@18b4aac2

        // 获得系统类加载器的加载路径
        String property = System.getProperty("java.class.path");
        System.out.println(property);
        /*
         * C:\Environments\jdk1.8.0_221\jre\lib\charsets.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\deploy.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\dnsns.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\jaccess.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\jfxrt.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\localedata.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\nashorn.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\sunec.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\sunjce_provider.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\sunmscapi.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\sunpkcs11.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\ext\zipfs.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\javaws.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\jce.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\jfr.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\jfxswt.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\jsse.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\management-agent.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\plugin.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\resources.jar;
         * C:\Environments\jdk1.8.0_221\jre\lib\rt.jar;
         * D:\IdeaProjects\reflection\out\production\reflection;
         * C:\applications\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar
         */


    }
}
